/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.base;

import edu.uci.ics.jung.graph.DelegateTree;
import java.awt.Color;
import java.awt.Paint;
import org.apache.commons.collections15.Transformer;

/**
 *
 * @author Asia
 */
public class VertexFill<V> implements Transformer<V, Paint> {

    @Override
    public Paint transform(V v) {

        if (v instanceof String) {
            String s = (String) v;
            if (s.startsWith("[0")) {
                return Color.BLUE;
            }
            return isClosed(s) ? Color.RED : Color.GREEN;
        }
        if (v instanceof DelegateTree) {
            return Color.YELLOW;
        }

        return null;

    }

    public boolean isClosed(String formula) {
        String[] array = formula.split(",");

        // w indexie 0 jest przetwarzana formuła
        for (int i = 1; i < array.length; i++) {
            if (!array[i].matches("^~")) {
                for (int j = 1; j < array.length; j++) {
                    if (array[j].matches("^~" + array[i] + "$")) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
}
